package com.iss.okair.service.assets;

import com.iss.common.StringTools;
import com.iss.common.UuidTools;
import com.iss.okair.db.entity.AssetsFinance;
import com.iss.okair.db.entity.Assetstrans;
import com.iss.okair.db.entity.Category;
import com.iss.okair.db.mapper.AssetsFinalMapper;
import com.iss.okair.db.mapper.CategoryMapper;
import com.iss.okair.db.model.AssetsFinalModle;
import org.aspectj.apache.bcel.generic.RET;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AssetsFianlService {
    @Resource
    private AssetsFinalMapper mapper;
    @Resource
    private CategoryMapper cmapper;
    public List<AssetsFinance> find(AssetsFinalModle model){
        return mapper.select(model);
    }
    public boolean save(AssetsFinance finance){
        if (StringTools.isNullOrEmpty(finance.getId())){
            //添加动作
            finance.setId(UuidTools.buildUUID());
            finance.setAssetscode(this.buildAssetsCodes(finance.getAssetstype()));
            return  mapper.add(finance)>=1 ? true:false;
        }else {
            //更新动作
            return mapper.update(finance)>=1 ? true:false;
        }
    }
    //添加一个编码方式为assetscode
    private String buildAssetsCodes(int category){
        Category currentCategory=cmapper.selectById(category);
         String temp= String.format("FIN%s-%06d",currentCategory.getCode(),mapper.countAll()+1);
        return  temp;
    }

}
